from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-24 14:02:21.228827
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 24, Nov, 2022
Time: 14:02:26
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.0405
Nobs: 850.000 HQIC: -51.3505
Log likelihood: 11140.9 FPE: 4.12278e-23
AIC: -51.5429 Det(Omega_mle): 3.71086e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299146 0.050351 5.941 0.000
L1.Burgenland 0.109636 0.034612 3.168 0.002
L1.Kärnten -0.106137 0.018438 -5.756 0.000
L1.Niederösterreich 0.210558 0.072366 2.910 0.004
L1.Oberösterreich 0.100668 0.068779 1.464 0.143
L1.Salzburg 0.251724 0.036696 6.860 0.000
L1.Steiermark 0.037101 0.048118 0.771 0.441
L1.Tirol 0.107557 0.039008 2.757 0.006
L1.Vorarlberg -0.060048 0.033621 -1.786 0.074
L1.Wien 0.054031 0.061458 0.879 0.379
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067616 0.103842 0.651 0.515
L1.Burgenland -0.030190 0.071382 -0.423 0.672
L1.Kärnten 0.047874 0.038026 1.259 0.208
L1.Niederösterreich -0.172867 0.149246 -1.158 0.247
L1.Oberösterreich 0.377645 0.141848 2.662 0.008
L1.Salzburg 0.288410 0.075681 3.811 0.000
L1.Steiermark 0.108207 0.099237 1.090 0.276
L1.Tirol 0.315939 0.080449 3.927 0.000
L1.Vorarlberg 0.023234 0.069339 0.335 0.738
L1.Wien -0.019447 0.126748 -0.153 0.878
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197784 0.026071 7.586 0.000
L1.Burgenland 0.092504 0.017922 5.162 0.000
L1.Kärnten -0.008746 0.009547 -0.916 0.360
L1.Niederösterreich 0.268538 0.037470 7.167 0.000
L1.Oberösterreich 0.115056 0.035613 3.231 0.001
L1.Salzburg 0.052700 0.019001 2.774 0.006
L1.Steiermark 0.016414 0.024915 0.659 0.510
L1.Tirol 0.098735 0.020198 4.888 0.000
L1.Vorarlberg 0.056067 0.017409 3.221 0.001
L1.Wien 0.111976 0.031822 3.519 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105045 0.026738 3.929 0.000
L1.Burgenland 0.047355 0.018380 2.576 0.010
L1.Kärnten -0.017288 0.009791 -1.766 0.077
L1.Niederösterreich 0.197122 0.038428 5.130 0.000
L1.Oberösterreich 0.279381 0.036523 7.649 0.000
L1.Salzburg 0.120203 0.019486 6.169 0.000
L1.Steiermark 0.101568 0.025552 3.975 0.000
L1.Tirol 0.123677 0.020714 5.971 0.000
L1.Vorarlberg 0.069093 0.017854 3.870 0.000
L1.Wien -0.026923 0.032635 -0.825 0.409
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130759 0.048408 2.701 0.007
L1.Burgenland -0.049525 0.033276 -1.488 0.137
L1.Kärnten -0.039526 0.017727 -2.230 0.026
L1.Niederösterreich 0.167420 0.069574 2.406 0.016
L1.Oberösterreich 0.140687 0.066126 2.128 0.033
L1.Salzburg 0.285123 0.035280 8.082 0.000
L1.Steiermark 0.031890 0.046262 0.689 0.491
L1.Tirol 0.163376 0.037503 4.356 0.000
L1.Vorarlberg 0.103787 0.032324 3.211 0.001
L1.Wien 0.067623 0.059087 1.144 0.252
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058566 0.038332 1.528 0.127
L1.Burgenland 0.042520 0.026350 1.614 0.107
L1.Kärnten 0.049753 0.014037 3.544 0.000
L1.Niederösterreich 0.227785 0.055092 4.135 0.000
L1.Oberösterreich 0.271666 0.052362 5.188 0.000
L1.Salzburg 0.058157 0.027937 2.082 0.037
L1.Steiermark -0.006863 0.036632 -0.187 0.851
L1.Tirol 0.156313 0.029697 5.264 0.000
L1.Vorarlberg 0.068315 0.025596 2.669 0.008
L1.Wien 0.074348 0.046788 1.589 0.112
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185586 0.045889 4.044 0.000
L1.Burgenland -0.004616 0.031544 -0.146 0.884
L1.Kärnten -0.060995 0.016804 -3.630 0.000
L1.Niederösterreich -0.086726 0.065953 -1.315 0.189
L1.Oberösterreich 0.192615 0.062683 3.073 0.002
L1.Salzburg 0.059658 0.033444 1.784 0.074
L1.Steiermark 0.225443 0.043854 5.141 0.000
L1.Tirol 0.495236 0.035551 13.930 0.000
L1.Vorarlberg 0.047611 0.030641 1.554 0.120
L1.Wien -0.051838 0.056011 -0.925 0.355
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158579 0.052278 3.033 0.002
L1.Burgenland -0.009150 0.035936 -0.255 0.799
L1.Kärnten 0.064788 0.019143 3.384 0.001
L1.Niederösterreich 0.202606 0.075135 2.697 0.007
L1.Oberösterreich -0.066975 0.071411 -0.938 0.348
L1.Salzburg 0.222349 0.038100 5.836 0.000
L1.Steiermark 0.113577 0.049959 2.273 0.023
L1.Tirol 0.084097 0.040501 2.076 0.038
L1.Vorarlberg 0.122133 0.034908 3.499 0.000
L1.Wien 0.109794 0.063809 1.721 0.085
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356848 0.030827 11.576 0.000
L1.Burgenland 0.008707 0.021191 0.411 0.681
L1.Kärnten -0.024705 0.011289 -2.188 0.029
L1.Niederösterreich 0.228433 0.044306 5.156 0.000
L1.Oberösterreich 0.157306 0.042110 3.736 0.000
L1.Salzburg 0.053163 0.022467 2.366 0.018
L1.Steiermark -0.018371 0.029460 -0.624 0.533
L1.Tirol 0.117682 0.023883 4.927 0.000
L1.Vorarlberg 0.071962 0.020585 3.496 0.000
L1.Wien 0.050323 0.037627 1.337 0.181
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043909 0.161283 0.192475 0.165671 0.132052 0.124475 0.070082 0.231260
Kärnten 0.043909 1.000000 0.002117 0.131568 0.045028 0.099411 0.427636 -0.050589 0.102157
Niederösterreich 0.161283 0.002117 1.000000 0.345385 0.166766 0.310986 0.128126 0.192197 0.341469
Oberösterreich 0.192475 0.131568 0.345385 1.000000 0.235961 0.340595 0.178049 0.180013 0.275537
Salzburg 0.165671 0.045028 0.166766 0.235961 1.000000 0.153197 0.145514 0.152767 0.140437
Steiermark 0.132052 0.099411 0.310986 0.340595 0.153197 1.000000 0.163167 0.148333 0.092672
Tirol 0.124475 0.427636 0.128126 0.178049 0.145514 0.163167 1.000000 0.121964 0.164306
Vorarlberg 0.070082 -0.050589 0.192197 0.180013 0.152767 0.148333 0.121964 1.000000 0.019880
Wien 0.231260 0.102157 0.341469 0.275537 0.140437 0.092672 0.164306 0.019880 1.000000